import api from '@/plugins/axios/api'

const mRequest = (apiName, param, callback, option) => {
  if (window.R.isNil(apiName)) {
    throw new Error('apiName is null or undefined')
  }
  if (window.R.isNil(api[apiName])) {
    throw new Error(`apiName "${apiName}" is doesn't exit`)
  }

  api[apiName](param, option)
    .then((value) => {
      if (window.R.isNil(value)) {
        return
      }
      callback(value)
    })
}

const mRequestPromise = (apiName, param, option) => {
  return new Promise(resolve => {
    mRequest(apiName, param, resolve, option)
  })
}

export {mRequest, mRequestPromise}
const getUrl = (apiName, param) => {
  return api[apiName](param, null, true)
}

export {getUrl}
